<?php if(sizeof($this->layout_options)>1):?>
<?php 
    $category    = !empty($this->pageValues['category'])?$this->pageValues['category']:null;
    $keyword        = !empty($this->pageValues['keyword'])?$this->pageValues['keyword']:null;
    $sort           = !empty($this->pageValues['sort'])?$this->pageValues['sort']:null;
	$form_submitted = !empty($this->pageValues['form_submitted'])?$this->pageValues['form_submitted']:null;
?>
<div id="dropdown_container">
	<div id="dropdown_value">
		<?php foreach($this->layout_options as $option):?>
		   <?php if($option['selected']):?>
				<?php if($option['value']==Core_Model_DbTable_Stores::LAYOUT_10xLIST):?>
					<span id="icon" class="icon selected_one">&nbsp;</span>
				<?php elseif($option['value']==Core_Model_DbTable_Stores::LAYOUT_3x12):?>
					<span id="icon" class="icon selected_second">&nbsp;</span>
				<?php elseif($option['value']==Core_Model_DbTable_Stores::LAYOUT_4x16):?>
					<span id="icon" class="icon selected_third">&nbsp;</span>
				<?php elseif($option['value']==Core_Model_DbTable_Stores::LAYOUT_3xAll):?>
					<span id="icon" class="icon selected_fourth">&nbsp;</span>
				<?php endif;?>
			<?php endif;?>
		<?php endforeach;?>
	</div>
	<button id="arrow_select" class="select_control">&nbsp;</button>
	<div class="dropdown_menu" id="dropdown_menu">
		<?php foreach($this->layout_options as $option):?>
			<?php if($option['value']==Core_Model_DbTable_Stores::LAYOUT_10xLIST):?>
				<a class="dropdown_item" href="#" id="list" value="list" layout="4"><span class="icon one">&nbsp;</span>&nbsp;List view</a>
			<?php elseif($option['value']==Core_Model_DbTable_Stores::LAYOUT_3x12):?>
				<a class="dropdown_item" href="#" id="grid3" value="grid3" layout="1"><span class="icon second">&nbsp;</span>&nbsp;Grid 3</a>
			<?php elseif($option['value']==Core_Model_DbTable_Stores::LAYOUT_4x16):?>
				<a class="dropdown_item" href="#" id="grid4" value="grid4" layout="2"><span class="icon third">&nbsp;</span>&nbsp;Grid 4</a>
			<?php elseif($option['value']==Core_Model_DbTable_Stores::LAYOUT_3xAll):?>
				<a class="dropdown_item" href="#" id="pinterest" value="pinterest" layout="8"><span class="icon fourth">&nbsp;</span>&nbsp;Pinterest</a>
			<?php endif;?>
		<?php endforeach;?>
	</div>
</div>
<script type="text/javascript">
	function hilightSelection()
	{
		if($('#icon').hasClass('selected_one'))
		{
			$('.icon.one').removeClass('one').addClass('selected_one');
		}
		if($('#icon').hasClass('selected_second'))
		{
			$('.icon.second').removeClass('second').addClass('selected_second');
		}
		if($('#icon').hasClass('selected_third'))
		{
			$('.icon.third').removeClass('third').addClass('selected_third');
		}
		if($('#icon').hasClass('selected_fourth'))
		{
			$('.icon.fourth').removeClass('fourth').addClass('selected_fourth');
		}
	}
    $(document).ready(function(){
		$('#arrow_select').click(function(){
			$('#dropdown_menu').toggle();
			hilightSelection()
		});		
		$('.icon').click(function(){
			$('#dropdown_menu').toggle();
			hilightSelection()
		});		
		$("body").click(function(e){
			if( !$(e.target).is('#arrow_select') && !$(e.target).is('.icon'))
			{
				$('#dropdown_menu').hide();
			}
		});
		$('.dropdown_item').click(function(e){
			e.preventDefault();
			$('#dropdown_menu').toggle();
			var value = $(this).attr('value');
			if(value=='list')
			{
				$('#dropdown_value').html('<span class="icon selected_one">&nbsp;</span>');
			}
			else if(value=='grid3')
			{
				$('#dropdown_value').html('<span class="icon selected_second">&nbsp;</span>');
			}
			else if(value=='grid4')
			{
				$('#dropdown_value').html('<span class="icon selected_third">&nbsp;</span>');
			}
			else if(value=='pinterest')
			{
				$('#dropdown_value').html('<span class="icon selected_fourth">&nbsp;</span>');
			}
			
			 var url = "<?php echo $this->pageUrl(array('controller' => 'index', 
                'action' => 'index', 'target' => 'index', 'layout' => null,'sort' => null, 
                'keyword' => $keyword, 'category' => $category,'form_submitted'=>$form_submitted,'page'=>null));?>" + "/layout/" + $(this).attr('layout');
            location.href = url;
		});
    });
</script>
<?php endif;?>